<cfparam name="dir" default="/">
<cfif isdefined('form.renamefileto')>
	<!---Remove illegal characters--->
	<cfset NewFileName = replace(form.renamefileto, "'", "", "ALL")>
	
	<cfset NewFileName = replace(NewFileName, '"', '', 'ALL')>
	<cfset NewFileName = replace(NewFileName, "*", "", "ALL")>
	<cfset NewFileName = replace(NewFileName, "&", "", "ALL")>
	<cfset NewFileName = replace(NewFileName, "(", "", "ALL")>
	<cfset NewFileName = replace(NewFileName, ")", "", "ALL")>
	<cfset NewFileName = replace(NewFileName, ";", "", "ALL")>
	<cfset NewFileName = replace(NewFileName, ":", "", "ALL")>
	<cfset NewFileName = replace(NewFileName, "!", "", "ALL")>

	<!---Now check to see if the extension is acceptable--->
	<cfset thepagename = '#NewFileName#'>
	<cfif right(thepagename, 4) IS '.exe' OR right(thepagename, 4) IS '.com' OR right(thepagename, 4) IS '.bat'>
		<cfoutput>
		<script language="javascript">
			alert('You did not specify a valid file extension. The file was NOT renamed.');
			location.replace('index.cfm?action=filemanager.browse&dir=#URLEncodedFormat(form.dir)#');
		</script>
		</cfoutput>
		<cfabort>
	</cfif>

	<cfset fullDespath = "#request.basepath##form.Dir#/#form.pagename#">
	<cfset fullDespath = replacenocase(FullDesPath, "//", "/", "ALL")>
	
	<cfset fullFrompath = "#request.basepath##form.dir#/#form.oldfile#">
	<cfset fullFrompath = replacenocase(FullFromPath, "//", "/", "ALL")>

	<cffile action = "rename"   
		source = "#fullfrompath#"   
		destination = "#fulldespath#"    
	>   
</cfif>
<cflocation url="index.cfm?c=filemanager&dir=#dir#">